import { GCellRenderer } from "../../../../../com/mui/controls/GCellRenderer";
import { ObjCreate } from "../../common/ObjCreate";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { LoaderHelp } from "../../../../common/display/LoaderHelp";
import { ResFileConst } from "../../../resource/ResFileConst";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GlobalClass } from "../../../../../com/mui/core/GlobalClass";
import { LoginSevenDaysInfo } from "./LoginSevenDaysInfo";
import { Language } from "../../../../../extend/language/Language";
import { ImagesConst } from "../../../resource/ImagesConst";
import { BaseItem } from "../../common/BaseItem";
import { ItemData } from "../../../resource/info/ItemData";
import { Cache } from "../../../cache/Cache";
import { FilterConst } from "../../../../component/gconst/FilterConst";
import { HighlightManager } from "../../../manager/HighlightManager";
import { FlyToNavbarTool } from "../../award/FlyToNavbarTool";
import { GButton } from "../../../../../com/mui/controls/GButton";
//class LoginSevenDaysRender
    
    export  class LoginSevenDaysRender extends GCellRenderer
    {
        constructor()
        {
            super();
            this._itemArr = [];
            this.initView();
            return;
        }

        /* internal  */initView(): void
        {
            this._dayTx = ObjCreate.createTextField("", 20, 9, 78, 20, this, GlobalStyle.textFormat5);
            this._dayTx.autoSize = flash.text.TextFormatAlign.CENTER;
            this._stBm = ObjCreate.createBitmap("", 18, 33, this);
            this._sp = new Object /* flash.display.Sprite */();
            this._sp.x = 125;
            addChild(this._sp);
            this._rewardBtn = ObjCreate.createGButton("", 584, 17, 84, 26, this, "ArenaRedBtn");
            this._rewardBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetReward);
            LoaderHelp.addResCallBack(ResFileConst.LoginSevenDays, this.onLoadBmResource);
            return;
        }

        protected onGetReward(arg1: Object /* flash.events.MouseEvent */): void
        {
            Dispatcher.dispatchEvent(new DataEvent(EventName.GoGetSevenDaysReward, this._info.day));
            return;
        }

        /* internal  */onLoadBmResource(): void
        {
            var loc1=null;
            this._loadedBool = true;
            if (this._info && this._info.day > 0) 
            {
                loc1 = "LoginSevenDays_" + this._info.day;
                this._stBm.bitmapData = GlobalClass.getBitmapData(loc1);
            }
            return;
        }

        public /* override */ set data(arg1: Object)
        {
            var loc1=null;
            var loc2=null;
            var loc3=null;
            var loc4=null;
            var loc5=0;
            var loc6=null;
            var loc7=0;
            super.data = arg1;
            this._info = arg1 as LoginSevenDaysInfo;
            this._itemArr = [];
            if (this._info) 
            {
                while (this._sp.numChildren > 0) 
                {
                    this._sp.removeChildAt(0);
                }
                this._dayTx.text = Language.getStringByParam(70902, this._info.day);
                loc1 = "LoginSevenDays_" + this._info.day;
                if (this._loadedBool) 
                {
                    this._stBm.bitmapData = GlobalClass.getBitmapData(loc1);
                }
                loc3 = [];
                loc5 = 0;
                while (loc5 < this._info.codeArr.length) 
                {
                    (loc4 = GlobalClass.getBitmap(ImagesConst.PackItemBg)).width = 38;
                    loc4.height = 38;
                    this._sp.addChild(loc4);
                    loc4.x = loc5 * 38 + 18;
                    loc4.y = 10;
                    loc2 = new BaseItem();
                    loc2.setSize(33, 33);
                    this._sp.addChild(loc2);
                    loc2.x = loc5 * 38 + 21;
                    loc2.y = 12;
                    if (((loc3 = this._info.codeArr[loc5])[0] & this._info.career) != 0) 
                    {
                        if (loc6 = new ItemData(parseInt(loc3[1]))) 
                        {
                            loc2.itemData = loc6;
                            loc2.amount = loc3[2];
                        }
                    }
                    this._itemArr.push(loc2);
                    ++loc5;
                }
                if (Cache.instance.role.entityInfo.level >= 36) 
                {
                    if ((loc7 = this._info.day - this._info.curLoginDay) != 0) 
                    {
                        if (loc7 < 0) 
                        {
                            if (this._info.states != 1) 
                            {
                                if (this._info.states != 0) 
                                {
                                    this._rewardBtn.label = Language.getString(70907);
                                    this._rewardBtn.enabled = false;
                                    this._rewardBtn.filters = [FilterConst.colorFilter];
                                }
                                else 
                                {
                                    this._rewardBtn.label = Language.getString(70903);
                                    this._rewardBtn.enabled = false;
                                    this._rewardBtn.filters = [FilterConst.colorFilter];
                                }
                            }
                            else 
                            {
                                this._rewardBtn.label = Language.getString(70908);
                                this._rewardBtn.enabled = true;
                                this._rewardBtn.filters = [];
                                HighlightManager.instance.glowEffectButton(this._rewardBtn, true);
                            }
                        }
                        else if (this._info.states != 1) 
                        {
                            if (this._info.states != 0) 
                            {
                                this._rewardBtn.label = Language.getStringByParam(70906, loc7);
                                this._rewardBtn.enabled = false;
                                this._rewardBtn.filters = [FilterConst.colorFilter];
                            }
                            else 
                            {
                                this._rewardBtn.label = Language.getString(70903);
                                this._rewardBtn.enabled = false;
                                this._rewardBtn.filters = [FilterConst.colorFilter];
                            }
                        }
                        else 
                        {
                            this._rewardBtn.label = Language.getString(70908);
                            this._rewardBtn.enabled = true;
                            this._rewardBtn.filters = [];
                            HighlightManager.instance.glowEffectButton(this._rewardBtn, true);
                        }
                    }
                    else if (this._info.states != 1) 
                    {
                        if (this._info.states != 0) 
                        {
                            this._rewardBtn.label = Language.getString(70905);
                            this._rewardBtn.enabled = false;
                            this._rewardBtn.filters = [FilterConst.colorFilter];
                        }
                        else 
                        {
                            this._rewardBtn.label = Language.getString(70903);
                            this._rewardBtn.enabled = false;
                            this._rewardBtn.filters = [FilterConst.colorFilter];
                        }
                    }
                    else 
                    {
                        this._rewardBtn.label = Language.getString(70908);
                        this._rewardBtn.enabled = true;
                        this._rewardBtn.filters = [];
                        HighlightManager.instance.glowEffectButton(this._rewardBtn, true);
                    }
                    if (this._info.flyFlag) 
                    {
                        this.flyPack();
                        this._info.flyFlag = false;
                    }
                }
                else 
                {
                    this._rewardBtn.label = Language.getString(70905);
                    this._rewardBtn.enabled = false;
                    this._rewardBtn.filters = [FilterConst.colorFilter];
                }
                this._rewardBtn.drawNow();
            }
            else 
            {
                while (this._sp.numChildren > 0) 
                {
                    this._sp.removeChildAt(0);
                }
            }
            return;
        }

        public flyPack(): void
        {
            var loc1=null;
            var loc2=0;
            if (this._itemArr.length > 0) 
            {
                loc2 = 0;
                while (loc2 < this._itemArr.length) 
                {
                    loc1 = this._itemArr[loc2] as BaseItem;
                    if (loc1 && loc1.bitmapdata) 
                    {
                        FlyToNavbarTool.flyToBackPack(loc1.bitmapdata, localToGlobal(new Object /* flash.geom.Point */(loc1.x + 125, loc1.y)));
                    }
                    ++loc2;
                }
            }
            return;
        }

        /* internal */ /* var */_info: LoginSevenDaysInfo;

        /* internal */ /* var */_dayTx: Object /* flash.text.TextField */;

        /* internal */ /* var */_stBm: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_sp: Object /* flash.display.Sprite */;

        /* internal */ /* var */_loadedBool: Boolean;

        /* internal */ /* var */_rewardBtn: GButton;

        /* internal */ /* var */_itemArr: Array<any>;
    }
